void page_deserialize(int number)
{
    if( place[number] == NULL )
    {
        printf("indeksSerialize.c l5\n");
        exit(1);
    }
    
    if( vec_last_article[number] == 1 )
    {
        return;
    }
    
    vec_last_article[number] = 1;
    fsetpos(serializeFile,  place[number] );

    fread( & (vec_article[number].len), sizeof(int), 1, serializeFile);
    
    vec_article[number].table = malloc( sizeof(int) * (vec_article[number].len) );
    fread( (vec_article[number].table), sizeof(int), vec_article[number].len , serializeFile);
    
    fread( & (vec_position[number].len), sizeof(int), 1, serializeFile);
    
    vec_position[number].table = malloc(sizeof(short) * vec_position[number].len );
    fread( (vec_position[number].table), sizeof(short), vec_position[number].len , serializeFile);    
    
    
}


void page_serialize(int number)
{
       vectorInt vi = vec_article[number];
       vectorShort vf = vec_position[number];
       
       place[number] = (fpos_t *) malloc( sizeof( fpos_t ) );
       if( fgetpos(serializeFile, place[number] ) )
       {
            printf("l64. Nieprawidlowa proba serializacji \n");
            exit(1);
       }
       fwrite( & (vi.len), sizeof(int), 1, serializeFile);
       fwrite( (vi.table), sizeof(int), vi.len , serializeFile);
       fwrite( & (vf.len), sizeof(int), 1, serializeFile);
       fwrite( (vf.table), sizeof(short), vf.len , serializeFile);
     
}

void page_initialize()
{
    fpos_t* top = (fpos_t *) malloc( sizeof( fpos_t ) );
    fread( top, sizeof(fpos_t), 1 , serializeFile );
    fsetpos(serializeFile, top );
    int i;
    for( i = 0 ; i < number_of_words ; i ++)
    {
        place[i] = (fpos_t *) malloc(sizeof( fpos_t) );
        if( fread( place[i] , sizeof(fpos_t) , 1 , serializeFile ) != 1)
        {
            printf("indeksSerialize.c l59 %d\n",i);
            exit(1);
        } 
    }    

}

void page_fullSerialize() 
{
    fpos_t* top = (fpos_t*) malloc( sizeof( fpos_t ) );
    
    fwrite( top , sizeof(fpos_t) , 1 , serializeFile ) ;
    int i;
    for( i = 0 ; i < number_of_words ; i ++)
    {
        page_serialize( i );
    }
    if( fgetpos(serializeFile, top ) )
    {
            printf("l148. Nieprawidlowa proba serializacji \n");
            exit(1);
    }
    for( i = 0 ; i < number_of_words ; i ++)
    {
       if( fwrite( place[i] , sizeof(fpos_t) , 1 , serializeFile ) != 1 )
       {
            printf("indeksSerialize.c l85\n");
            exit(1);
       }
    }
    rewind( serializeFile );
    fwrite( top , sizeof(fpos_t) , 1 , serializeFile ) ;    
}
